package com.common.util;

import java.util.Random;

public class RadomString {

    private static final Random random = new Random();
    private static final char[] sourceArray = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
    private static final int lengthSourceArray =  sourceArray.length;

    public static final String generateRandomString(int length) {

             if (length < 1) {
                 throw new IllegalArgumentException();
             }

             char [] randBuffer = new char[length];
             for (int i=0; i<randBuffer.length; i++) {
                 randBuffer[i] = sourceArray[random.nextInt(lengthSourceArray)];
             }
             return new String(randBuffer);
    }
}